package esay.array;

/**
 * 加一操作
 * @author ruizhou
 * @date 26.02.2018
 */
public class PlusOne {

    private static int[] plusOne(int[] digits) {
        for (int i = digits.length-1; i >= 0; i--) {
            if (digits[i] < 9) {
                digits[i] = digits[i] + 1;
                return digits;
            }
            digits[i] = 0;
        }

        int[] newDigits = new int[digits.length +1];
        newDigits[0] = 1;
        return newDigits;
    }

    public static void main(String[] args) {
        int[] digits = {9};
        System.out.println(plusOne(digits));
    }
}
